package com.liyk.shop.component.rabbitmq;

import com.liyk.shop.domain.entity.ProductKillOrder;
import com.liyk.shop.dto.MailMsgDto;
import com.liyk.shop.utils.MailService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = RabbitQueue.ORDER_EMAIL)
public class OrderReceiver {

    @Autowired
    private MailService mailService;

    @Autowired
    private Environment env;

    @RabbitHandler
    public void process(ProductKillOrder order) {
        MailMsgDto msgDto = new MailMsgDto();
        msgDto.setFrom(env.getProperty("mail.sender"));
        msgDto.setTo(order.getUserEmail());
        msgDto.setSubject("主题名称");
        msgDto.setContent("购买成功，订单号为：" + order.getId());
        mailService.sendSimpleMail(msgDto);
    }

}
